package wzh.crm.db;

import org.json.JSONObject;
import org.jsoup.Connection;

import wzh.crm.vo.OpportunityVo;

/**
 * Created by wangzehao on 2016/6/19.
 */
public class OpportunityDB extends WebServiceDB<OpportunityVo> {
    @Override
    protected OpportunityVo toBean(JSONObject json) throws Exception {
        OpportunityVo model=new OpportunityVo();
        model.setId(json.optInt("opportunityid"));
        model.set商机标题(json.optString("opportunitytitle"));
        model.set对应客户编号(json.optInt("customerid"));
        model.set预计销售金额(json.optDouble("estimatedamount"));
        model.set成功率(json.optInt("successrate"));
        model.set预计签单日期(parseDate(json.optString("expecteddate")));
        model.set状态(json.optInt("opportunitystatus"));
        model.set渠道商(json.optString("channel"));
        model.set商机类型(json.optInt("businesstype"));
        model.set商机获取日期(parseDate(json.optString("acquisitiondate")));
        model.set商机来源(json.optString("opportunitiessource"));
        model.set获取该商机的员工ID(json.optInt("staffid"));
        model.set备注(json.optString("opportunityremarks"));
        return model;
    }

    @Override
    protected void toPost(OpportunityVo model, Connection c) {
        c.data("opportunityid",Integer.toString(model.getId()));
        c.data("opportunitytitle",model.get商机标题());
        c.data("customerid",Integer.toString(model.get对应客户编号()));
        c.data("estimatedamount",Double.toString(model.get预计销售金额()));
        c.data("successrate",Double.toString(model.get成功率()));
        c.data("expecteddate",dateToString(model.get预计签单日期()));
        c.data("opportunitystatus",Integer.toString(model.get状态()));
        c.data("channel",model.get渠道商());
        c.data("businesstype",Integer.toString(model.get商机类型()));
        c.data("acquisitiondate",dateToString(model.get商机获取日期()));
        c.data("opportunitiessource",model.get商机来源());
        c.data("staffid",Integer.toString(model.get获取该商机的员工ID()));
        c.data("opportunityremarks",model.get备注());
    }

    @Override
    protected String listQueryMethod() {
        return "common_opportunity_json";
    }

    @Override
    protected String idQueryMethod() {
        return "opportunity_query_json";
    }

    @Override
    protected String createMethod() {
        return "opportunity_create_json";
    }

    @Override
    protected String modifyMethod() {
        return "opportunity_modify_json";
    }
}
